import Vue from 'vue';
import VueRouter, { RouteConfig } from 'vue-router';
import Home from '../views/Home.vue';

Vue.use(VueRouter);

const routes: RouteConfig[] = [
  {
    path: '/page/',
    name: 'Home',
    component: Home,
    meta: {
      title: 'home'
     },
    children: [
      {
        path: 'index',
        name: 'Index',
        meta: {
          title: 'index'
        },
        component: () => import('../views/Index.vue')
      },
      {
        path: 'name',
        name: 'Name',
        meta: {
          title: 'name'
        },
        component: () => import('../views/Name.vue')
      }
    ]
  },
  {
    path: '/page/about',
    name: 'About',
    meta: {
      title: 'About'
     },
    component: () => import('../views/About.vue'),
  },
  {
    path: '/page/formBox',
    name: 'FormBox',
    meta: {
      title: 'FormBox'
     },
    component: () => import('../views/form'),
  },
  {
    path: '/page/403',
    name: '403',
    meta: {
      title: '403'
     },
    component: () => import('@/page/error/403.vue')
  },
  {
    path: '/page/*',
    name: '404',
    meta: {
      title: '404'
     },
    component: () => import('@/page/error/404.vue')
  }
];
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
});


// 路由守卫
router.beforeEach((to: any, from: any, next: Function): void => {
  document.title = `${to.meta.title} | my page`;
  // console.log(to, 123, from);
  next();
  // next('/page/');
});
export default router;
